<template id="shareLi">
    <div>
        <div class="shareLi_top">
            <img @click="back()" src="../image/blue_da.png" alt="">
            <h6>领取分享礼</h6>
        </div>

        <div class="shareLI_con"  v-for="(item, index) in items">
            <div class="shareLi_center">
                <div class="shareLi_1"><img v-bind:src="item.img" alt=""></div>
                <div class="shareLi_2">
                    <p>{{item.name}}</p>
                    <p></p>
                    <p><time>{{item.tips}}</time></p>
                </div>
                <div class="shareLi_3" v-if="item.status == 0">
                    <span @click="addCart(item.goods_id,item.gift_id)">去领取></span>
                </div>
                <div class="shareLi_3" v-else>
                    <span >已领取</span>
                </div>
            </div>
        </div>

        <div class="share_foot">
            <img src="../image/share_1.png" alt="" @click="addCartList()">
        </div>
    </div>
</template>
<script>
    export default {
        name:'shareLi',
        data(){
            return{
                items:[],
                mode:'share_user_list',
            }
        },
        mounted:function(){
            //初始化
            var page    = 1;
            var is_more = 0;
            this.get_share(this.mode,page,is_more);

        },
        methods:{
            back:function(){
                this.$router.push('/center');
            },
            addCartList(){
                 if(this.items){
                    let goods_all = []; let ids = [];
                    for (var i in this.items) {

                        //引子
                        if(this.items[i]['status'] == 0){
                            ids[this.items[i]['goods_id']] = this.items[i]['goods_id'];
                       
                            let k1 = 'num_'+this.items[i]['goods_id'];
                            if(goods_all[k1]){
                                goods_all[k1] += 1;
                            }else{
                                goods_all[k1] = 1;
                            }

                            let k2 = 'gift_'+this.items[i]['goods_id'];
                            if(goods_all[k2]){
                                 goods_all[k2] += this.items[i]['gift_id'] +',';
                            }else{
                                 goods_all[k2] = this.items[i]['gift_id'] +',';
                            }
                        }
                      
                    }
                    if(ids.length){
                         for (var i in ids) {
                            let k1 = 'num_'+ids[i];
                            let k2 = 'gift_'+ids[i];

                            let goods_num = goods_all[k1];
                            let gift_id  = goods_all[k2];
                            gift_id = gift_id.substring(0,gift_id.length-1) 

                            this.GLOBAL.addCart(this,ids[i],goods_num,gift_id);
                         }

                         //跳转购物车
                         this.$router.push('/shop');
                         
                    }
                 }
            },
            addCart(goods_id,gift_id){
                this.GLOBAL.addCart(this,goods_id,1,gift_id);
                //跳转购物车
                this.$router.push('/shop');
            },
            get_share(mode,page,is_more){
                let url  = this.GLOBAL.BaseUrl+'/mobile/api/index.php?c=Share&m='+mode;
                let Data = this.GLOBAL.dataParam();
                
                this.$ajax.post(url,Data).then((res) => {
                    let temp = res.data;
                    if(temp.code == 200){
                        if(is_more){
                            this.GLOBAL.merge_array(this.items,temp.data);
                            $("#page").attr('data-page',page);
                            
                        }else{
                            this.items = temp.data;
                        }
                    
                    }else{
                         this.GLOBAL.center_error(this,temp);
                    }
                })
            },

        },

    }
</script>
<style>
    .share_foot{
        width:100%;
        height:0.82rem;
        position:absolute;
        bottom:0;
        left:0;
    }
    .share_foot img{
        display:block;
        height:0.82rem;
        width:100%;
    }
    /*内容部分*/
    .shareLi_3 span{
        width:1.2rem;
        height:0.42rem;
        font-size:0.28rem;
        text-align:center;
        line-height:0.42rem;
        color:#ffffff;
        background:#67c5fd;
        border-radius:0.2rem;
        position:absolute;
        top:0.52rem;
    }
    .shareLi_3{
        width:1.2rem;
        height:1.62rem;
        position:relative;
    }
    .shareLi_2 p:nth-of-type(1){
        height:0.24rem;
        font-size:0.28rem;
        text-indent:0.22rem;
        line-height:0.24rem;
        color:#fc39b2;
    }
    .shareLi_2 p:nth-of-type(2){
        height:0.38rem;
        line-height:0.38rem;
        color:#cfcfcf;
        font-size:0.24rem;
        text-indent:0.22rem;
    }
    .shareLi_2 p:nth-of-type(3){
        height:1.15rem;
        line-height:1.15rem;
        text-indent:0.22rem;
        color:#cfcfcf;
        font-size:0.22rem;
    }
    .shareLi_2 p:nth-of-type(3) time{
        color:#2eaffc;
    }
    .shareLi_2{
        width:3.28rem;
        height:1.62rem;
    }
    .shareLi_1{
        width:1.43rem;
        height:1.62rem;
    }
    .shareLi_1 img{
        display:block;
        width:1.43rem;
        height:1.43rem;
        margin:0.18rem 0;
    }
    .shareLI_con{
        width:100%;
        min-height:1.78rem;
    }
    .shareLi_center{
        width:5.9rem;
        height:1.62rem;
        border-bottom:0.01rem solid #f0f0f0;
        display:flex;
        padding-top:0.15rem;
        margin:0 auto;
    }
    /*top*/
    .shareLi_top{
        width:100%;
        height:0.79rem;
        border-bottom:1px solid #f0f0f0;
        position:relative;
    }
    .shareLi_top img:nth-of-type(1){
        height:0.36rem;
        width:0.36rem;
        display:block;
        position:absolute;
        left:0.25rem;
        top:0.25rem;
    }
    .shareLi_top h6{
        height:0.79rem;
        line-height:0.79rem;
        text-align:center;
        font-size:0.26rem;
        color:#2eaffc;
        font-weight:normal;
    }
</style>